package com.xiaoKe.zhonghzu.ui.fzxz;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.xiaoKe.zhonghzu.databinding.ItemGatherBinding;
import com.xiaoKe.zhonghzu.global.bean.ClFzData;
import com.xiaoKe.zhonghzu.global.bean.GeneralData;
import com.xiaoKe.zhonghzu.global.tool.SPUtils;
import com.xiaoKe.zhonghzu.ui.onClick.OnClickListenerPositionInt;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * @ProjectName : xiaoke-pad-zhongzhu
 * @Author : Shijingna
 * @Time : 2024/11/25 13:13
 * @Description : 文件描述
 */
public class GatherAdapter extends RecyclerView.Adapter<GatherAdapter.ViewHolder> {
    List<GeneralData> list;

    public GatherAdapter(List<GeneralData> list) {
        this.list = list;
    }

    @NonNull
    @NotNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        ItemGatherBinding binding = ItemGatherBinding.inflate(inflater, parent, false);
        return new ViewHolder(binding);
    }

    @Override
    public void onBindViewHolder(@NonNull @NotNull ViewHolder holder, int position) {
        GeneralData generalData = list.get(position);
        holder.binding.icon.setImageResource(generalData.getState());
        holder.binding.name.setText(generalData.getK().toString());
        holder.binding.icon.setOnClickListener(new View.OnClickListener() { //新增弹窗
            @Override
            public void onClick(View view) {
                onClickListenerPositionInt.onItemClick(position);
            }
        });
        List<ClFzData> dtjFragmentList = SPUtils.getDataList("DtjFragment", ClFzData.class);
        if (null != dtjFragmentList && dtjFragmentList.size() != 0) {
            holder.binding.ztjSum.setText(dtjFragmentList.size() + "");
            holder.binding.ztjSumCardView.setVisibility(position == 3 ? View.VISIBLE : View.GONE);
        } else {
            holder.binding.ztjSumCardView.setVisibility(View.GONE);
        }

    }

    @Override
    public int getItemCount() {
        return null == list ? 0 : list.size();
    }


    public class ViewHolder extends RecyclerView.ViewHolder {
        final ItemGatherBinding binding;

        ViewHolder(ItemGatherBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }

    public OnClickListenerPositionInt onClickListenerPositionInt;

    public void setOnClickListenerPositionInt(OnClickListenerPositionInt onClickListenerPositionInt) {
        this.onClickListenerPositionInt = onClickListenerPositionInt;
    }
}
